package com.laolang.pluto.common.web.jackson;

import cn.hutool.core.date.DatePattern;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
 * @author laolang
 * @date 2021-08-15 06:06
 */
public class LocalTimeSerialize extends JsonSerializer<LocalTime> {
    private final DateTimeFormatter formatter;

    public LocalTimeSerialize() {
        this.formatter = DateTimeFormatter.ofPattern(DatePattern.NORM_TIME_PATTERN);
    }

    @Override
    public void serialize(LocalTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        gen.writeString(value.format(formatter));
    }
}
